home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 5685 / 5685.xpi / chrome / vodpod.jar / content / overlay.js < prev    next >
Text File  |  2008-06-27  |  5KB  |  104 lines

  1. var vodpod_button = {
  2.   prefix: 'savevideo@vodpod.com',
  3.   button_id: 'vodpod-toolbar-button',
  4.   loaded: false,
  5.     
  6.   onLoad: function() {
  7.     try {
  8.     // initialization code
  9.     if (!this.loaded) {
  10.         this.loaded = true;
  11.         this.strings = document.getElementById("vodpod-strings");
  12.         var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  13.         // The 'target' is the target for the button. This could be a dedicated site (like wordpress.com)
  14.         // or could be generic.
  15.         this.target = prefs.getCharPref("extensions." + this.prefix + ".target");
  16.          
  17.         setTimeout("VodpodDelayedInit('" + this.prefix + "','" + this.button_id + "');", 0);
  18.     }    
  19.     }catch(e) {alert(e);}
  20.   },
  21.   onMenuItemCommand: function(e) {
  22.     try {
  23.         content.window.stop();
  24.         //var script = content.document.createElement('script');
  25.         //var src = 'http://www.vodpod.com/javascripts/bookmarklet.js?' + parseInt(Math.random()*9999);
  26.         //script.src = src;
  27.         //content.document.body.appendChild(script);
  28.  
  29.         vodpod.share_video(content.document, this.target, content.window);
  30.     } catch(e) {
  31.         alert(e);
  32.     }
  33.   },
  34.   onToolbarButtonCommand: function(e) {
  35.     // just reuse the function above.  you can change this, obviously!
  36.     vodpod_button.onMenuItemCommand(e);
  37.   },
  38.   search_dialog: function(e) {
  39.       window.openDialog("chrome://vodpod/content/search_popup.xul", 'video_search','chrome=yes,resizable=yes,centerscreen,width=400,height=140');
  40.   },
  41.   go_help: function(e) {
  42.     var help_url = "http://www.vodpod.com/vpbutton/help";
  43.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  44.     try {
  45.       help_url = prefs.getCharPref("extensions." + prefix + ".help");
  46.     } catch(e) {}
  47.     var tabBrowser = top.getBrowser();
  48.     if (tabBrowser) {
  49.       tabBrowser.loadOneTab(help_url, null, null, null, false, false);
  50.     }
  51.   }
  52. };
  53. // Our init logic is to always install the button if it's missing, but only show the help
  54. // page if the user has never installed the extension. Once the user has seen the help page,
  55. // then we write a preference so we don't show it again. However, the way firefox works is that
  56. // that preference will persist even if the user removes our extension. This gives these results:
  57. // --Help page only shown after first ever install of the extension
  58. // --Toolbar button will always be added to the toolbar on Firefox startup
  59. // --If user just removes button from toolbar, it will be re-added next time. They have to remove
  60. // the extension to get rid of it permanently.
  61. function VodpodDelayedInit(prefix, button_id) {
  62.     VodpodAddToolbarItem(button_id);
  63.     
  64.     var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
  65.     if (!prefs.prefHasUserValue("extensions." + prefix + ".installed")) {
  66.       prefs.setBoolPref("extensions." + prefix + ".installed", true);
  67.       var help_url = "http://www.vodpod.com/vpbutton/start";
  68.       try {
  69.         help_url = prefs.getCharPref("extensions." + prefix + ".start");
  70.       } catch(e) {}
  71.       var tabBrowser = top.getBrowser();
  72.       if (tabBrowser) {
  73.         tabBrowser.loadOneTab(help_url, null, null, null, false, false);
  74.       }
  75.     }
  76. }
  77. function VodpodAddToolbarItem(button_id)
  78. {
  79.   var firefoxnav = document.getElementById("navigation-toolbar") || document.getElementById("nav-bar"); // use "nav-bar" in Firefox 2 and earlier
  80.   //alert("nav toolbar: " + firefoxnav);
  81.    var curSet = firefoxnav.currentSet;
  82.    if (curSet.indexOf(button_id) == -1)
  83.    {
  84.      var set;
  85.      // Place the button before the urlbar
  86.      if (curSet.indexOf("urlbar-container") != -1)
  87.        set = curSet.replace(/urlbar-container/, button_id + ",urlbar-container");
  88.      else  // at the end
  89.        set = firefoxnav.currentSet + "," + button_id;
  90.      firefoxnav.setAttribute("currentset", set);
  91.      firefoxnav.currentSet = set;
  92.      document.persist("nav-bar", "currentset"); // Firefox 2
  93.      document.persist("navigation-toolbar", "currentset"); // Firefox 3 and later
  94.      // If you don't do the following call, funny things happen
  95.      try {
  96.           //alert("CustomizeDone call");
  97.        BrowserToolboxCustomizeDone(true);
  98.      }
  99.      catch (e) { } 
  100.    }
  101. }
  102.  
  103. window.addEventListener("load", function(e) { vodpod_button.onLoad(e); }, false);
  104.